package com.config;

import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

import javax.servlet.MultipartConfigElement;
import javax.servlet.ServletRegistration;

public class MainInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {

    /**
     * 图片上传本地图床
     */
    public static final String uploadLocalPath= "D:\\Desktop\\photo";
    @Override
    protected Class<?>[] getRootConfigClasses() {
        return new Class[]{MainConfiguration.class};   //基本的Spring配置类，一般用于业务层配置
    }

    @Override
    protected Class<?>[] getServletConfigClasses() {
        return new Class[]{WebConfiguration.class};  //配置DispatcherServlet的配置类、主要用于Controller等配置
    }

    @Override
    protected String[] getServletMappings() {
        return new String[]{"/"};    //匹配路径，与上面一致
    }

    @Override
    protected void customizeRegistration(ServletRegistration.Dynamic registration) {
        // 直接通过registration配置Multipart相关配置，必须配置临时上传路径，建议选择方便打开的
        // 同样可以设置其他属性：maxFileSize, maxRequestSize, fileSizeThreshold
//        String projectPath = System.getProperty("user.dir");
//        String uploadPath = projectPath+"\\src\\main\\webapp\\WEB-INF\\resources";
        registration.setMultipartConfig(new MultipartConfigElement(uploadLocalPath));
    }
}
